package com.jayway.opengl.tutorial;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;

public class HighlightView extends View {

	private int mHighlightHeight;
	private Paint mPaint = new Paint();
	private RectF mHighlightRect = new RectF();

	public HighlightView(Context context) {
		super(context);
	}

	public HighlightView(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	public HighlightView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
	}

	public int getHighlightHeight() {
		return mHighlightHeight;
	}

	public void setHighlightHeight(int highlightHeight) {
		mHighlightHeight = highlightHeight;
	}

	public RectF getHightlightRect() {
		return mHighlightRect;
	}

	@Override
	protected void onDraw(Canvas canvas) {
		super.onDraw(canvas);

		final int w = getWidth();
		final int h = getHeight();

		mPaint.reset();
		mPaint.setAlpha(0xAA);
		canvas.drawRect(0, 0, w, (h - mHighlightHeight) / 2, mPaint);
		canvas.drawRect(0, (h + mHighlightHeight) / 2, w, h, mPaint);

		mPaint.setColor(Color.WHITE);
		mPaint.setStyle(Paint.Style.STROKE);
		mPaint.setStrokeWidth(2f);
		canvas.drawLine(0, (h - mHighlightHeight) / 2, w,
				(h - mHighlightHeight) / 2, mPaint);
		canvas.drawLine(0, (h + mHighlightHeight) / 2, w,
				(h + mHighlightHeight) / 2, mPaint);
		canvas.drawLine(0, (h - mHighlightHeight) / 2, 0,
				(h + mHighlightHeight) / 2, mPaint);
		canvas.drawLine(w, (h - mHighlightHeight) / 2, w,
				(h + mHighlightHeight) / 2, mPaint);

		mHighlightRect.set(getLeft(), getTop()
				+ (getHeight() - mHighlightHeight) / 2.0f, getRight(),
				getBottom() - (getHeight() - mHighlightHeight) / 2.0f);
	}
}
